<template>
  <div class="left-line" ref="target"></div>
</template>

<script setup>
import { onMounted, ref, defineProps, watch } from "vue";
import * as echarts from "echarts";
const props = defineProps({
  file_id_show: {
    type: Array,
    required: true,
  },
  data_volt_show: {
    type: Array,
    required: true,
  },
});

const target = ref(null);
let mChart = null;
onMounted(() => {
  mChart = echarts.init(target.value);
  renderChart();
});

const renderChart = () => {
  let options = {
    title: {
      text: "总体电压曲线图",
      x: "center",
      y: 0,
      textStyle: {
        color: "#B4B4B4",
        fontSize: 16,
        fontWeight: "normal",
      },
    },
    backgroundColor: "#191E40",
    tooltip: {
      trigger: "axis",
      backgroundColor: "rgba(255,255,255,0.1)",
      axisPointer: {
        type: "shadow",
        label: {
          show: true,
          backgroundColor: "#7B7DDC",
        },
      },
      textStyle: {
        color: "white",
      },
    },
    grid: {
      x: "8%",
      width: "82%",
      y: "8%",
    },
    xAxis: {
      data: props.data_volt_show[0].map((item, index) => {
        return index;
      }),
      axisLine: {
        lineStyle: {
          color: "#B4B4B4",
        },
      },
      axisTick: {
        show: false,
      },
      name: "时间节点",
      nameLocation: "center",
      nameTextStyle: {
        padding: [20, 0, 0, 0],
        color: "white",
      },
    },
    yAxis: {
      type: "value",
      min: 230,
      max: 245,
      name: "用户电压值",
      nameLocation: "center",
      nameTextStyle: {
        padding: [0, 0, 40, 35],
        color: "white",
      },
    },
    // 注释多条曲线
    series: props.data_volt_show.map((item, index) => {
      return {
        name: props.file_id_show[index],
        type: "line",
        symbol: "circle",
        symbolSize: 6,
        data: item, // 折线图的数据
      };
    }),
  };
  options && mChart.setOption(options);
};
window.addEventListener("resize", function () {
  mChart.resize();
});
watch(
  () => props.file_id_show,
  () => {
    renderChart();
  }
);
</script>

<style lang="scss" scoped>
.left-line {
  width: 95%;
  height: 95%;
  padding: 24px;
}
</style>
